﻿'插件公共模块
Enum '代码主题
   CLR_WINDOW = 0 '"窗口背景", 1 Or 2
   CLR_TEXT         ' "普通文本", 0
   CLR_KEYWORD      ' "FB关键词", 0
   CLR_API          '"API", 0
   CLR_PREPROCESSOR '"预处理", 0
   CLR_STRINGS      '"字符串", 0
   CLR_OPERATORS    '"操作符", 0
   CLR_COMMENTS     '"注释", 0
   CLR_HIGHLIGHTED  '"当前行", 1 Or 2
   CLR_CARET        '"光标", 1 Or 4
   CLR_FOLDMARGIN   '"折叠区", 1 Or 2
   CLR_FOLDSYMBOL   '"折叠符号", 1
   CLR_LINENUMBERS  '"行号", 0
   CLR_INDENTGUIDES '"缩进虚线", 1
   CLR_SELECTION    '"选择", 1
   CLR_Bookmark     '"书签", 1
   CLR_Lib          '"函数库", 0
End Enum
Enum '主题：
   Themes_标题栏
   Themes_工具栏
   Themes_窗口
   Themes_分组标签
   Themes_分组选择
   Themes_普通标签
   Themes_标签选择
End Enum
Type TYPE_COLORS
   nFg            As COLORREF '文字色
   nBg            As COLORREF '背景色 窗口主题只用这个，而且是 HSB值，不是RGB
   bFontBold      As Long     '粗体
   bFontItalic    As Long     '斜体
   bFontUnderline As Long     '下划线
End Type
Type TYPE_THEMES '主题
   Caption    As String '主题名称
   colors(29) As TYPE_COLORS
End Type

Type pezi '配置
   fw                   As Long     '功能区宽度
   fh                   As Long     '提示区高度
   fg                   As Long     '代码窗口在那边 0：在左边 1：在右边
   Move_p               As Long     '弃用，但不可删除，因为控件也有这个类
   DefaultProjectPath   As String   '默认工程文件夹
   MultipleInstances    As Long     '   允许开多个VisualFreeBasic
   SaveProjectOnExit    As Long     '退出VisualFreeBasic 自动保存文件
   AutoSave             As Long     '自动保存（每1分钟保存1次）
   AutoSaveTime         As UInteger ' 自动保存时间 =timeGetTime
   AutoToFiles          As Long     '自动关联文件（*.ffp;*.bas）
   CheckMirror          As Long     '使用镜像（每次打开工程时同步到下面文件夹里）
   MirrorFolder(2)      As String   ' 镜像文件夹
   AutoBackup           As Long     '自动备份（敲键盘100下将产生备份文件，保存7天）
   BackupFolder         As String   ' 自动备份文件夹
   StartupPage          As Long     ' 启动VisualFreeBasic后
   SyntaxHighlighting   As Long     '语法突出显示
   Codetips             As Long     '代码提示
   AutoComplete         As Long     '自动完成
   ConfineCaret         As Long     '限制插入符号
   HighlightCurrentLine As Long     '突出显示当前行
   TabIndentSpaces      As Long     '制表符缩进空格
   AutoIndentation      As Long     '自动缩进
   AllowVfbLibrary      As Long     '允许修改 VFB 库文件
   FoldMargin           As Long     '显示折叠区
   LineNumbering        As Long     '显示行编号
   IndentGuides         As Long     '显示缩进参考线
   RightEdge            As Long     '行字符右边界线
   RightEdgePosition    As Long     '右边界线位置
   TabSize              As Long     'TAB空格字符数
   EditorFontname       As String   '编辑字体名称
   EditorFontCharSet    As String   '编辑字体字符集
   EditorFontsize       As Long     '编辑器字体大小
   KeywordCase          As Long     ' "Original Case"  '关键字大小写
   FBWINCompiler32      As String   '32位编译器
   FBWINCompiler64      As String   '64位编译器
   CompilerSwitches     As String   '编译器附加选项
   HideCompileResults   As Long     '如果在编译过程中没有发生错误则不提示编译结果
   MinimizeOnCompile    As Long     '运行已编译的程序时最小化 VisualFreeBasic
   ChineseCodeToEnglish As Long     '中文代码转换为英文（适合不支持中文代码的编译器）
   FBKeywords           As String   'FB关键词，从   .\Settings\freebasic_keywords.txt  读取
   APIKeywords          As String   'API关键词，从   .\Settings\freebasic_keywords.txt  读取
   LibKeywords          As String   '函数库关键词，自动提取
   FBKeywordsC          As String   'FB关键词，小写，火花编辑器必须提供小写
   APIKeywordsC         As String   'API关键词
   LibKeywordsC         As String   '函数库关键词
   SuppressNotify       As BOOLEAN  ' 暂时禁止Scintilla事件
   WinProChin           As Long     '窗口属性名显示中文
   WinFont              As String   '窗口控件默认字体
   Languages            As String   '多国语言文件夹
   TitleBarPath         As Long     '标题栏显示工程文件路径
   TitleBarVFB          As Long     '标题栏显示VFB版本号
   ShowSpaces           As Long     '可以使空白可见  0=正常模式不显示  1=点和箭头 2=缩进后的点和箭头 3=缩进点和箭头
   FunStart             As Long     '显示函数开始行底色
   FunEnd               As Long     '显示函数结束分隔线
End Type

Dim Shared ThemeCode            As TYPE_THEMES ,ThemeWin As TYPE_THEMES '主题
Dim Shared GetOpAPP             As Function() As Any Ptr '获取VFB 的 配置指针 ，使用函数必须带() 不然就是本函数指针，如 Dim vfbOp As pezi Ptr = GetOpAPP()
Dim Shared GetExeAPP            As Function() As Any Ptr '获取EXE 的 APP指针 ，使用函数必须带() 不然就是本函数指针，如 Dim vfbAPP As APP_TYPE Ptr = GetExeAPP()
Dim Shared GetProRunFileEx      As Function(p As Long ,n As Long ,r As ZString Ptr)          As Long '{2.0 带输出路径+输出文件.1 输出路径.2 输出文件（不带路径）.3 工程文件 .4 工程文件夹.5 工程名称}
Dim Shared GetImgFormEx         As Function(yName As String ,nImg As Long ,r As ZString Ptr) As Long '打开图像管理器，获取图像文件名称,yName=原名 nImg=0 任意图像 =1 ICO图标  r 为返回值
Dim Shared OpenHelp             As Sub(nHelp As String) '打开帮助文档，只能指定帮助文件下的帮助文档，nHelp 为文件名，不包含路径
Dim Shared OpenColorDialog      As Function(cHwnd As hWnd ,nColor As Long) As hWnd ' 打开色彩对话框，返回窗口句柄，选择好颜色将会 PostMessage cHwnd,9898,9898,颜色值
Dim Shared GetMainWinHandle     As Function()                  As hWnd             '获取EXE主窗口句柄 使用函数必须带() 不然就是本函数指针，如 a=GetMainWinHandle()
Dim Shared IsMultiLanguage      As Function()                  As Long             '当前工程是不是启用多国语言 使用函数必须带() 不然就是本函数指针
Dim Shared CurProIsChildWindow  As Function(chuanko As String) As Long             '当前工程中，窗口是不是存在以及是不是子窗口属性。
Dim Shared CurProSetChildWindow As Sub(hWndForm As hWnd) '当前工程中，让主窗口填充子窗口属性的窗口。
Dim Shared Menu_Add_Jilu        As Sub(h As HMENU ,tFont As HFONT ,zz As Long ,Colors As Long ,C As Long ,S As Long ,T As String ,tKey As String)                    '增加菜单，用法见例题
Dim Shared InsertTool           As Sub(position As Long ,IcoWchr As Long ,Colour As Long ,CommandID As Long ,xTyep As Long ,xTips As String ,FileImg As String = "") '插入工具栏按钮
Dim Shared HotUpdateMyCodeBase  As Sub() '热更新我的代码库

'position As Long  '按钮位置
'IcoWchr As Long  '宽字符符号值
'Colour As Long  '显示的颜色
'CommandID As Long  '菜单的命令ID号
'xTyep As Long  ' 属性  =0始终有效 =1代码编辑器时有效 =2窗口区有效 =3有工程时有效 =4窗口和代码
'xTips As String  ' 提示
Dim Shared OpenGongCen As Sub(nFile As CWSTR) '打开工程，nFile 是带路径的工程文件名
Dim Shared CreateTab   As Function(nPos As Long ,nText As String ,xTips As String ,nHwnd As hWnd ,wIco As Long = 0) As Long '增加Tab项目，失败返回0 成功非0
'nPos  位置，=0主工作区 =1侧边区 =2底部区
'nText 名称
'xTips 提示
'nHwnd 窗口句柄，需要自己加载个新窗口给它，窗口要带 子窗口属性，且指定父窗口才可以。CreateTab(2,"百度","",Form1.Show(GetMainWinHandle()))
'wIco  图标，字体图标的数值
Dim Shared CloseTab As Function(nPos As Long ,nHwnd As hWnd) As Long '关闭 Tab项目
'nPos  位置，=0 增加在大窗口里，=1 在 库、属性这小窗口里 =2 在底部
'nHwnd 窗口句柄 CreateTab 创建时的窗口句柄

Dim Shared CurrentProNewAdd As Function(p As Long ,utf8_Text As String) As Long '当前工程新增 p=0 窗口、p=1 模块 p=2资源 ,成功返回非0 ，失败为0
'utf8_Text utf8编码，为新增的代码或窗口代码（如同VFB里新增的模板一样内容）

'有关代码编辑器操作（采用 Scintilla 火花编辑器 引擎） ===================
Dim Shared GetFocusCodeEdit     As Function() As hWnd '获取当前代码编辑器的主窗口，在其包含 2个代码编辑器和2个Combo控件。使用函数必须带() 不然就是本函数指针
Dim Shared CodeEditMsg          As Function(ByVal pSci As Any Ptr ,ByVal wMsg As UINT ,ByVal wp As wParam ,ByVal LP As lParam) As LResult '代码编辑器直接消息处理函数（Scintilla 消息处理函数，比系统的 SendMessage 效率高）
Dim Shared GetCurrentSci        As Function()                    As Any Ptr             '获取当前编辑器 Scintilla 句柄 ，使用函数必须带() 不然就是本函数指针,可以用此句柄直接操作 Scintilla 控件，居然看Scintilla官方文档。 CodeEditMsg(pSci, SCI_SETANCHOR, nPos, 0)
Dim Shared InsertText           As Function(Utf8_Text As String) As Long                ' 插入文本到当前编辑器当前位置，文本必须是UTF8
Dim Shared AppendText           As Function(Utf8_Text As String) As Long                ' 增加文本到当前编辑器尾部，返回插入在第几行
Dim Shared GetCurrentText       As Function(Utf8_Text As String) As Long                '' 获取当前编辑器 全部文本
Dim Shared SetCurrentText       As Function(Utf8_Text As String) As Long                '' 设置当前编辑器 全部文本
Dim Shared GetCurrentLineNumber As Function()                    As Long                '' 获取当前编辑器 获取当前行号，使用函数必须带() 不然就是本函数指针
Dim Shared SetCurrentLineText   As Function(nLine As Long ,Utf8_Text As String) As Long '' 获取当前编辑器 某行文本
Dim Shared GetCurrentLineText   As Function(nLine As Long ,Utf8_Text As String) As Long '' 设置当前编辑器 某行文本
Dim Shared GetCurrentSelText    As Function(Utf8_Text As String)                As Long '' 设置当前编辑器 选择文本
Dim Shared GoCurrentLine        As Sub(VisibleLine As Long ,CurrentLine As Long) ' 当前编辑器 到指定行

'以下是直接对VFB里的代码数据库操作，具体功能见数据控件用法 =================
Dim Shared SQLiteBox_Find        As Function(index As Long ,Table As CWSTR ,Cond As CWSTR ,rs() As String ,Col As CWSTR = "*" ,Orderby As CWSTR = "" ,Page As Long = 1 ,Pagesize As Long = 0) As Long
Dim Shared SQLiteBox_FindOne     As Function(index As Long ,Table As CWSTR ,Cond As CWSTR ,rs() As String ,Col As CWSTR = "*" ,Orderby As CWSTR = "") As Long
Dim Shared SQLiteBox_FindOnly_p  As Function(index As Long ,Table As CWSTR ,Cond As CWSTR ,Col As CWSTR ,Orderby As CWSTR ,OutStr As String)          As Long
Dim Shared SQLiteBox_Exec        As Function(index As Long ,Sql_Utf8 As String) As Long
Dim Shared SQLiteBox_Update      As Function(index As Long ,Table As CWSTR ,Cond As CWSTR ,upList As CWSTR)                   As Long
Dim Shared SQLiteBox_UpdateUtf   As Function(index As Long ,Table_Utf8 As String ,Cond_Utf8 As String ,upList_Utf8 As String) As Long
Dim Shared SQLiteBox_DeleteItem  As Function(index As Long ,Table As CWSTR ,Cond As CWSTR)              As Long
Dim Shared SQLiteBox_Count       As Function(index As Long ,Table As CWSTR ,Cond As CWSTR = "")         As Long
Dim Shared SQLiteBox_AddItem     As Function(index As Long ,Table As CWSTR ,nList As CWSTR)             As Long
Dim Shared SQLiteBox_AddItemUtf  As Function(index As Long ,Table_Utf8 As String ,nList_Utf8 As String) As Long
Dim Shared SQLiteBox_Transaction As Sub(index As Long ,BeginEnd As Long) '事务，BeginEnd=0 开始 BeginEnd=1 结束
Dim Shared SQLiteBox_Vacuum      As Sub(index As Long)
Dim Shared SQLiteBox_MaxID       As Function(index As Long ,Table As CWSTR ,nField As CWSTR ,Cond As CWSTR = "") As Long
Dim Shared SQLiteBox_ErrMsg_p    As Function(index As Long ,outStr As String) As Long
'index =0为公库 =1为私库 =2当前编辑器（纯内存数据库）

'函数声明

Sub SetFunctionAddress() '设置函数地址
   Dim library As Any Ptr
   GetOpAPP             = DyLibSymbol(library ,"GETOPAPP")             '获取VFB 的 配置指针
   GetExeAPP            = DyLibSymbol(library ,"GETEXEAPP")            '获取EXE 的 APP指针
   GetProRunFileEx      = DyLibSymbol(library ,"GETPRORUNFILEEX")      '得到工程编译的文件名,p=0为当前工程{2.0 带输出路径+输出文件.1 输出路径.2 输出文件（不带路径）.3 工程文件 .4 工程文件夹}
   GetImgFormEx         = DyLibSymbol(library ,"GETIMGFORMEX")         '打开图像管理器，获取图像文件名称,yName=原名 nImg=0 任意图像 =1 ICO图标
   OpenHelp             = DyLibSymbol(library ,"OPENHELP")             '只能指定帮助文件下的帮助文档
   OpenColorDialog      = DyLibSymbol(library ,"OPENCOLORDIALOG")      ' 打开色彩对话框，返回窗口句柄，选择好颜色将会 PostMessage cHwnd,9898,9898,颜色值
   GetMainWinHandle     = DyLibSymbol(library ,"GETMAINWINHANDLE")     '获取EXE主窗口句柄
   IsMultiLanguage      = DyLibSymbol(library ,"ISMULTILANGUAGE")      '当前工程是不是启用多国语言
   CurProIsChildWindow  = DyLibSymbol(library ,"CURPROISCHILDWINDOW")  '当前工程中，窗口是不是存在以及是不是子窗口属性。
   CurProSetChildWindow = DyLibSymbol(library ,"CURPROSETCHILDWINDOW") '当前工程中，让主窗口填充子窗口属性的窗口。
   Menu_Add_Jilu        = DyLibSymbol(library ,"MENU_ADD_JILU")        '增加菜单
   InsertTool           = DyLibSymbol(library ,"INSERTTOOL")
   OpenGongCen          = DyLibSymbol(library ,"OPENGONGCEN")         '打开工程
   CreateTab            = DyLibSymbol(library ,"CREATETAB")           ' 增加Tab项目，失败返回0 成功非0
   CloseTab             = DyLibSymbol(library ,"CLOSETAB")            ' 增加Tab项目，失败返回0 成功非0
   CurrentProNewAdd     = DyLibSymbol(library ,"CURRENTPRONEWADD")    '
   HotUpdateMyCodeBase  = DyLibSymbol(library ,"HOTUPDATEMYCODEBASE") '热更新我的代码库
   
   GetFocusCodeEdit     = DyLibSymbol(library ,"GETFOCUSCODEEDIT")     '
   CodeEditMsg          = DyLibSymbol(library ,"CODEEDITMSG")          '
   GetCurrentSci        = DyLibSymbol(library ,"GETCURRENTSCI")        '
   InsertText           = DyLibSymbol(library ,"INSERTTEXT")           '
   AppendText           = DyLibSymbol(library ,"APPENDTEXT")           '，返回插入在第几行
   GetCurrentText       = DyLibSymbol(library ,"GETCURRENTTEXT")       '
   SetCurrentText       = DyLibSymbol(library ,"SETCURRENTTEXT")       '
   GetCurrentLineNumber = DyLibSymbol(library ,"GETCURRENTLINENUMBER") '
   SetCurrentLineText   = DyLibSymbol(library ,"SETCURRENTLINETEXT")   '
   GetCurrentLineText   = DyLibSymbol(library ,"GETCURRENTLINETEXT")   '
   GetCurrentSelText    = DyLibSymbol(library ,"GETCURRENTSELTEXT")    '
   GoCurrentLine        = DyLibSymbol(library ,"GOCURRENTLINE")        '
   
   SQLiteBox_Find        = DyLibSymbol(library ,"SQLITEBOX_FIND")       '具体功能见数据控件用法
   SQLiteBox_FindOne     = DyLibSymbol(library ,"SQLITEBOX_FINDONE")    '具体功能见数据控件用法
   SQLiteBox_Exec        = DyLibSymbol(library ,"SQLITEBOX_EXEC")       '具体功能见数据控件用法
   SQLiteBox_Update      = DyLibSymbol(library ,"SQLITEBOX_UPDATE")     '具体功能见数据控件用法
   SQLiteBox_DeleteItem  = DyLibSymbol(library ,"SQLITEBOX_DELETEITEM") '具体功能见数据控件用法
   SQLiteBox_Count       = DyLibSymbol(library ,"SQLITEBOX_COUNT")
   SQLiteBox_AddItem     = DyLibSymbol(library ,"SQLITEBOX_ADDITEM")
   SQLiteBox_FindOnly_p  = DyLibSymbol(library ,"SQLITEBOX_FINDONLY")
   SQLiteBox_AddItemUtf  = DyLibSymbol(library ,"SQLITEBOX_ADDITEMUTF")
   SQLiteBox_UpdateUtf   = DyLibSymbol(library ,"SQLITEBOX_UPDATEUTF")
   SQLiteBox_Vacuum      = DyLibSymbol(library ,"SQLITEBOX_VACUUM")
   SQLiteBox_MaxID       = DyLibSymbol(library ,"SQLITEBOX_MAXID")
   SQLiteBox_ErrMsg_p    = DyLibSymbol(library ,"SQLITEBOX_ERRMSG")
   SQLiteBox_Transaction = DyLibSymbol(library ,"SQLITEBOX_TRANSACTION")
   
   '处理多国语言 -----
   Dim op       As pezi Ptr     = GetOpAPP()
   Dim ExeApp   As APP_TYPE Ptr = GetExeAPP()
   Dim langFile As String       = ExeApp->Path & "Languages\" & op->Languages & "\Languages.txt"
   vfb_LoadLanguage(langFile ,App.EXEName)
   
   
End Sub

Function SQLiteBox_FindOnly(index As Long ,Table As CWSTR ,Cond As CWSTR ,Col As CWSTR = "*" ,Orderby As CWSTR = "")As String
   '跨模块不可以返回 String ，需要个转换函数
   Dim OutStr As String
   SQLiteBox_FindOnly_p(index ,Table ,Cond ,Col ,Orderby ,OutStr)
   Function = OutStr
End Function
Function SQLiteBox_ErrMsg(index As Long)As String  
   '跨模块不可以返回 String ，需要个转换函数
   Dim OutStr As String
   SQLiteBox_ErrMsg_p(index ,OutStr)
   Function = OutStr
End Function

